<!DOCTYPE html>
<html lang="zh-Hans">

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0,maximum-scale=1,minimum-scale=1,user-scalable=no">

    <link rel="stylesheet" href="./css/index.css" />
</head>

<body>
    <h1>JavaScript 循环与选择</h1>

    <h2>选择</h2>
    <p>选择，用于程序运算过程中的分支操作。</p>
    <pre>

// 随意修改paramA、paramB、paramC的值，来查看结果
let paramA = 1; 
let paramB = 2;
let paramC = 3;


// 选择示例1
if (paramA > paramB) {
    console.log("paramA > paramB");
}

// 选择示例2
if (paramA > paramB) {
    console.log("paramA > paramB");
}
else {
    console.log("paramA <= paramB");
}

// 选择示例3
if (paramA > paramB) {
    console.log("paramA > paramB");
}
else if (paramA > paramC) {
    console.log("paramA > paramB && paramA > paramC");
}
else {
    console.log("paramA <= paramB");
}
    </pre>

    <h2>循环</h2>
    <p>循环，用于程序运算过程中的重复的操作。</p>
    <h3>for循环</h3>

    <pre>
let arr = ['Apple', 'Google', 'Microsoft'];
let i;
for (i = 0; i < arr.length; i++) {
    console.log(arr[i]);
}
    </pre>

    <h3>for in 循环</h3>
    <pre>
let a = ['A', 'B', 'C'];
for (let i in a) {
    console.log(i); // '0', '1', '2'
    console.log(a[i]); // 'A', 'B', 'C'
}
    </pre>


    <h3>while 循环</h3>

    <pre>
let x = 0;
let n = 99;
while (n > 0) {
    x = x + n;
    n = n - 2;
}
console.log(x); // 2500
    </pre>

</body>

</html>